/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.stockkeeper;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;

/**
 *
 * @author ibisuser1
 */
public class PersistenceManager {
    
    private static EntityManager em;
    
    public static EntityManager getEntityManager() {
        if (em == null)
        {
            EntityManagerFactory emf = Persistence.createEntityManagerFactory("StockKeeperPU");
            em = emf.createEntityManager();
        }
        return em;
    }
    
    public static void rollback() {
        if (em!=null && em.getTransaction()!=null && em.getTransaction().isActive()) {
            em.getTransaction().rollback();
        }
    }
}
